28 #ifndef _spoton_utilities_h_
29 #define _spoton_utilities_h_
31 #include <QDesktopWidget>
38 static void centerWidget(QWidget *child, QWidget *parent)
48 if(X11->isSupportedByWM(ATOM(_NET_WM_FULL_PLACEMENT)))
59 int extrah = 0, extraw = 0, scrn = 0;
62 parent = parent->window();
67 scrn = QApplication::desktop()->screenNumber(parent);
68 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
69 else if(QApplication::desktop()->isVirtualDesktop())
70 scrn = QApplication::desktop()->screenNumber(QCursor::pos());
73 scrn = QApplication::desktop()->screenNumber(child);
75 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
76 desk = QApplication::desktop()->availableGeometry(scrn);
78 desk = QGuiApplication::screens().value(scrn) ?
79 QGuiApplication::screens().value(scrn)->geometry() : QRect();
82 QWidgetList list = QApplication::topLevelWidgets();
84 for(
int i = 0; (extrah == 0 || extraw == 0) && i < list.size(); ++i)
86 QWidget *current = list.at(i);
88 if(current && current->isVisible())
90 int frameh = current->geometry().y() - current->y();
91 int framew = current->geometry().x() - current->x();
93 extrah = qMax(extrah, frameh);
94 extraw = qMax(extraw, framew);
98 if(extrah == 0 || extrah >= 40 || extraw == 0 || extraw >= 10)
106 QPoint pp = parent->mapToGlobal(QPoint(0,0));
108 p = QPoint(pp.x() + parent->width() / 2,
109 pp.y() + parent->height() / 2);
112 p = QPoint(desk.x() + desk.width() / 2, desk.y() + desk.height() / 2);
114 p = QPoint(p.x() - child->width() / 2 - extraw,
115 p.y() - child->height() / 2 - extrah);
117 if(p.x() + extraw + child->width() > desk.x() + desk.width())
118 p.setX(desk.x() + desk.width() - child->width() - extraw);
123 if(p.y() + extrah + child->height() > desk.y() + desk.height())
124 p.setY(desk.y() + desk.height() - child->height() - extrah);